package com.ruoyi.chat.controller;

import com.ruoyi.chat.domain.FhChatFriend;
import com.ruoyi.chat.service.IFhChatFriendService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 好友Controller
 * 
 * @author ruoyi
 * @date 2024-11-11
 */
@RestController
@RequestMapping("/chat/friend")
public class FhChatFriendController extends BaseController
{
    @Autowired
    private IFhChatFriendService fhChatFriendService;

    /**
     * 查询好友列表
     */
    @PreAuthorize("@ss.hasPermi('chat:friend:list')")
    @GetMapping("/list")
    public TableDataInfo list(FhChatFriend fhChatFriend)
    {
        startPage();
        List<FhChatFriend> list = fhChatFriendService.selectFhChatFriendList(fhChatFriend);
        return getDataTable(list);
    }

    /**
     * 导出好友列表
     */
    @PreAuthorize("@ss.hasPermi('chat:friend:export')")
    @Log(title = "好友", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FhChatFriend fhChatFriend) throws IOException {
        List<FhChatFriend> list = fhChatFriendService.selectFhChatFriendList(fhChatFriend);
        ExcelUtil<FhChatFriend> util = new ExcelUtil<FhChatFriend>(FhChatFriend.class);
        util.exportExcel(response, list, "好友数据");
    }

    /**
     * 获取好友详细信息
     */
    @PreAuthorize("@ss.hasPermi('chat:friend:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(fhChatFriendService.selectFhChatFriendById(id));
    }

    /**
     * 新增好友
     */
    @PreAuthorize("@ss.hasPermi('chat:friend:add')")
    @Log(title = "好友", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FhChatFriend fhChatFriend)
    {
        return toAjax(fhChatFriendService.insertFhChatFriend(fhChatFriend));
    }

    /**
     * 修改好友
     */
    @PreAuthorize("@ss.hasPermi('chat:friend:edit')")
    @Log(title = "好友", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FhChatFriend fhChatFriend)
    {
        return toAjax(fhChatFriendService.updateFhChatFriend(fhChatFriend));
    }

    /**
     * 删除好友
     */
    @PreAuthorize("@ss.hasPermi('chat:friend:remove')")
    @Log(title = "好友", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fhChatFriendService.deleteFhChatFriendByIds(ids));
    }
}
